<script setup>
import { getEnterpriseDetailAPI } from "@/pages/enterpriseManager/firmManager/apis/index.js"

const table = ref([])
const detailEnterprise = reactive({
})
const previewURL = "https://view.officeapps.live.com/op/view.aspx?src="
const router = useRouter()

async function getDetail() {
  const res = await getEnterpriseDetailAPI(router.currentRoute.value.params.id)
  table.value = res.data.rent
  Object.assign(detailEnterprise, res.data)
}

onMounted(() => {
  getDetail()
})
</script>

<template>
  <div class="detail-enterprise">
    <header class="add-header">
      <el-page-header content="查看企业" @back="$router.back()" />
    </header>
    <main class="add-main">
      <el-card style="max-width: 1650px; margin-left:20px;">
        <template #header>
          <div class="card-header">
            <span>企业信息</span>
          </div>
        </template>
        <p>企业名称：{{ detailEnterprise?.name }}</p>
        <p>注册地址：{{ detailEnterprise?.registeredAddress }}</p>
        <p>法人：{{ detailEnterprise?.legalPerson }}</p>
        <p>所在行业：{{ detailEnterprise?.industryName }}</p>
        <p>联系人：{{ detailEnterprise?.contact }}</p>
        <p>联系人电话：{{ detailEnterprise?.contactNumber }}</p>
      </el-card>
      <div class="form-container">
        <div class="title">
          租赁记录
        </div>
        <div class="table-container">
          <el-table
            :data="table"
            style="width: 100%"
            border
          >
            <el-table-column
              prop="index"
              label="序号"
              width="50"
              type="index"
            />
            <el-table-column
              prop="name"
              label="租赁楼宇"
              width="180"
            />
            <el-table-column
              label="租赁起止时间"
              width="280"
            >
              <template #default="{ row }">
                {{ row.startTime }} - {{ row.endTime }}
              </template>
            </el-table-column>
            <el-table-column
              label="租赁合同(点击预览)"
            >
              <template #default="{ row }">
                <el-button type="text">
                  <a :href="`${previewURL}${row.contractUrl}`" target="_blank">
                    {{ row.contractName }}
                  </a>
                </el-button>
              </template>
            </el-table-column>
            <el-table-column
              prop="createTime"
              label="录入时间"
            />
            <el-table-column
              prop="address"
              label="操作"
            >
              <template #default="{ row }">
                <el-button type="text">
                  合同下载
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </main>
  </div>
</template>

<style scoped lang="scss">
.detail-enterprise {
  height: 100vh;

  .add-header {
    display: flex;
    align-items: center;
    padding: 0 20px;
    height: 64px;

    .left {
      span {
        margin-right: 4px;
      }
      .arrow {
        cursor: pointer;
      }
    }

    .right {
      text-align: right;
    }
  }

  .add-main {
    padding: 20px 130px;

    .form-container {
      margin-bottom: 20px;
      .title {
        height: 60px;
        line-height: 60px;
        padding-left: 20px;
      }
    }
    .table-container {
      padding: 20px;
    }
    .preview {
      img {
        width: 100px;
      }
    }
  }
}
</style>
